﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TheVoiceOfSnake
{
    public class SpeechRecognizer
    {
        private List<Frame> Frames;
        private List<double> ExtractedParameters;
        private Segmentator Segmentator;
        private HammingWindowHandler Windowing;
        private FastFourierTransformer FFT;
        private MFCCHandler MFCC;
        private Writer Writer;

        public SpeechRecognizer() 
        {
            Frames = new List<Frame>();
            ExtractedParameters = new List<double>();
            Segmentator = new Segmentator();
            Windowing = new HammingWindowHandler();
            FFT = new FastFourierTransformer();
            MFCC = new MFCCHandler();
            Writer = new Writer();
        }

        public string ExtractParameters(byte[] input) 
        {
            Frames.AddRange(Segmentator.SegmentInputValues(input));
            Windowing.Windowing(Frames);
            FFT.Transform(Frames, FastFourierTransformationType.FFT);
            MFCC.ComputeModuleValues(Frames);
            ExtractedParameters.AddRange(MFCC.ExtractFinalParameters(Frames, Segmentator.Frequency));
            return Writer.ConvertParams(ExtractedParameters);
            //Writer.SavaParams(ExtractedParameters);
            
            /* wersja z IFFT */
            //Frame result = new Frame();
            //result.SetTableOfValues(MFCC.ExtractFinalParameters(Frames, Segmentator.Frequency));
            //List<Frame> tmp = new List<Frame>();
            //tmp.Add(result);
            //FFT.Transform(tmp, FastFourierTransformationType.IFFT);
            //Writer.SavaParams(tmp.First().GetTableOfValues());
        }
    }
}
